package com.letao.server.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * OSS服务配置类
 */
@Data
@Component
@Configuration
@ConfigurationProperties(prefix = "aliyun.oss")
public class OSSConfig {
    /**
     * 域名
     */
    private String endpoint;
    /**
     * 接口密钥ID
     */
    private String accessKeyId;
    /**
     * 接口密钥
     */
    private String accessKeySecret;
    /**
     * Bucket名称
     */
    private String bucketName;

    public final String host = "https://seu-letao.oss-cn-beijing.aliyuncs.com/";

    @Bean(destroyMethod = "shutdown")
    public OSS createOSS() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}
